/*
 * Copyright © 2017 eqxiu.com 北京中网易企秀科技有限公司  All rights reserved.
 */

package cn.hermit.nio.http;

import java.util.Date;

/**
 * @author JackGao 高建国
 * @description //TODO 设计说明
 * @date 29/5/2017
 */
public interface Http {

    enum Verb {
        CONNECT, DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT, TRACE
    }

    enum Version {
        HTTP10, HTTP11
    }

    enum ParamIn {

        QUERY("query"), PATH("path"), HEADER("header"), FORM("formData"), BODY("body");

        private String value;

        ParamIn(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }
    }

    enum ParamType {
        STRING, NUMBER, INTEGER, BOOLEAN, ARRAY, FILE
    }

    enum ParamRealType {

        INTEGER, LONG, FLOAT, DOUBLE, STRING, BYTE, BINARY, BOOLEAN, DATE, DATETIME, PASSWORD;

        public static String getSwaggerType(ParamRealType paramRealType) {
            switch (paramRealType) {
                case INTEGER:
                    return "integer";
                case LONG:
                    return "integer";
                case FLOAT:
                    return "number";
                case DOUBLE:
                    return "number";
                case STRING:
                    return "string";
                case BYTE:
                    return "string";
                case BINARY:
                    return "string";
                case BOOLEAN:
                    return "boolean";
                case DATE:
                    return "string";
                case DATETIME:
                    return "string";
                case PASSWORD:
                    return "string";
                default:
                    return "string";
            }
        }

        public static String getSwaggerType(Class<?> paramRealType) {
            if (int.class == paramRealType || Integer.class == paramRealType || long.class == paramRealType || Long.class == paramRealType) {
                return "integer";
            } else if (float.class == paramRealType || Float.class == paramRealType || double.class == paramRealType || Double.class == paramRealType) {
                return "number";
            } else if (String.class == paramRealType || byte.class == paramRealType || Byte.class == paramRealType
                    || char.class == paramRealType || Character.class == paramRealType
                    || Date.class == paramRealType) {
                return "string";
            } else if (boolean.class == paramRealType || Boolean.class == paramRealType) {
                return "boolean";
            } else {
                return "string";
            }
        }

        public static ParamRealType getRealType(Class<?> paramRealType) {
            if (int.class == paramRealType || Integer.class == paramRealType) {
                return INTEGER;
            } else if (long.class == paramRealType || Long.class == paramRealType) {
                return LONG;
            } else if (float.class == paramRealType || Float.class == paramRealType) {
                return FLOAT;
            } else if (double.class == paramRealType || Double.class == paramRealType) {
                return DOUBLE;
            } else if (String.class == paramRealType) {
                return STRING;
            } else if (byte.class == paramRealType || Byte.class == paramRealType) {
                return BYTE;
            } else if (char.class == paramRealType || Character.class == paramRealType) {
                return BINARY;
            } else if (Date.class == paramRealType) {
                return DATE;
            } else if (boolean.class == paramRealType || Boolean.class == paramRealType) {
                return BOOLEAN;
            } else {
                return null;
            }
        }

        public static ParamRealType getRealType(String paramRealTypeName) {
            if (int.class.getName().equals(paramRealTypeName) || Integer.class.getName().equals(paramRealTypeName)) {
                return INTEGER;
            } else if (long.class.getName().equals(paramRealTypeName) || Long.class.getName().equals(paramRealTypeName)) {
                return LONG;
            } else if (float.class.getName().equals(paramRealTypeName) || Float.class.getName().equals(paramRealTypeName)) {
                return FLOAT;
            } else if (double.class.getName().equals(paramRealTypeName) || Double.class.getName().equals(paramRealTypeName)) {
                return DOUBLE;
            } else if (String.class.getName().equals(paramRealTypeName)) {
                return STRING;
            } else if (byte.class.getName().equals(paramRealTypeName) || Byte.class.getName().equals(paramRealTypeName)) {
                return BYTE;
            } else if (char.class.getName().equals(paramRealTypeName) || Character.class.getName().equals(paramRealTypeName)) {
                return BINARY;
            } else if (Date.class.getName().equals(paramRealTypeName)) {
                return DATE;
            } else if (boolean.class.getName().equals(paramRealTypeName) || Boolean.class.getName().equals(paramRealTypeName)) {
                return BOOLEAN;
            } else {
                return null;
            }
        }

        public static String getDataFormat(ParamRealType paramRealType) {
            switch (paramRealType) {
                case INTEGER:
                    return "int32";
                case LONG:
                    return "int64";
                case FLOAT:
                    return "float";
                case DOUBLE:
                    return "double";
                case STRING:
                    return "";
                case BYTE:
                    return "byte";
                case BINARY:
                    return "binary";
                case BOOLEAN:
                    return "";
                case DATE:
                    return "date";
                case DATETIME:
                    return "date-time";
                case PASSWORD:
                    return "password";
                default:
                    return "";
            }
        }


    }

    int CODE_200 = 200;
    int CODE_404 = 404;
    int CODE_500 = 500;

    String OK_200 = "HTTP/1.1 200 OK";
    String NEWLINE = "\r\n";
    String NOT_FOUND_404 = "HTTP/1.1 404 Not Find";
    String SERVER_ERROR_500 = "HTTP/1.1 500 Internal Server Error";
    String CONTENT_TYPE = "Content-Type";
    String CONNECTION = "Connection";
    String CONTENT_LENGTH = "Content-Length";
    String KEEP_ALIVE = "keep-alive";
    String CONTENT_ENCODING = "Content-Encoding";
    String ACCEPT = "Accept";
    String ACCEPT_ENCODING = "Accept-Encoding";
    String LAST_MODIFIED = "Last-Modified";
    String GZIP = "gzip";


    String MEDIA_TYPE_TEXT_PLAIN = "text/plain";

    String MEDIA_TYPE_TEXT_HTML = "text/html";

    String MEDIA_TYPE_TEXT_JS = "text/javascript";

    String MEDIA_TYPE_APPLICATION_JSON = "application/json";

    String MEDIA_TYPE_APPLICATION_XML = "application/XML";

    String MEDIA_TYPE_APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded";

}
